﻿namespace Acl.WinFormHosting
{
    internal class MultiShellContext : ApplicationContext
    {
        private int openForms;

        public MultiShellContext(params Form[] forms)
        {
            this.openForms = forms.Length;
            foreach (var form in forms)
            {
                form.FormClosed += OnFormClosed;
                form.Show();
            }
        }

        private void OnFormClosed(object? s, FormClosedEventArgs args)
        {
            if (Interlocked.Decrement(ref this.openForms) == 0)
            {
                ExitThread();
            }
        }
    }
}
